package view;

import java.util.List;

import view.Tabs.HomePageGUI;
import view.Tabs.ProfileGUI;
import view.Tabs.SearchGUI;
import view.Windows.LoginGUI;
import view.Windows.UpdateDBGUI;

import commons.Entities.Comment;
import commons.Entities.LegenCharacter;
import commons.Entities.LegenCharacterThin;
import commons.Entities.LegenDate;
import commons.Entities.Review;
import commons.Entities.SearchResults;

public class ViewFunctions {

	private final static ViewFunctions INSTANCE = new ViewFunctions();

	public static ViewFunctions get() {
		return INSTANCE;
	}

	public ViewFunctions() {

	}

	public void updateGUIUserFavorites(final List<LegenCharacterThin> favorites) {
		HomePageGUI.get().getMainDisp().asyncExec(new Runnable() {

			public void run() {

				ProfileGUI.get().updateFavorites(favorites);

			}
		});
	}

	public void updateGUIUserLegeDateDetails(final List<LegenDate> legenDates) {
		HomePageGUI.get().getMainDisp().asyncExec(new Runnable() {

			public void run() {
				ProfileGUI.get().updateUserDates(legenDates);

			}
		});
	}

	public void updateGUICharacterDetails(final LegenCharacter character) {
		HomePageGUI.get().getMainDisp().asyncExec(new Runnable() {

			public void run() {

				HomePageGUI.get().openCharacterTab(character);

			}
		});
	}

	public void updateGUICharacterComments(final List<Comment> comments, final Integer characterID) {
		HomePageGUI.get().getMainDisp().asyncExec(new Runnable() {

			public void run() {

				HomePageGUI.get().characterPages.get(characterID).getCharGUI().updateCharacterComments(comments);

			}
		});
	}

	public void updateGUISearchResults(final SearchResults searchResults) {
		SearchGUI.get().getMainDisp().asyncExec(new Runnable() {

			public void run() {

				SearchGUI.get().updateSearchResults(searchResults);

			}
		});
	}

	public void updateGUITopTenCharacters(final List<LegenCharacterThin> characters) {
		HomePageGUI.get().getMainDisp().asyncExec(new Runnable() {

			public void run() {
				HomePageGUI.get().showTopList("Top Ten Rated Characters", characters, 30, 160);
			}
		});
	}

	public void updateGUIBottomTenCharacters(final List<LegenCharacterThin> characters) {
		HomePageGUI.get().getMainDisp().asyncExec(new Runnable() {

			public void run() {
				HomePageGUI.get().showTopList("Bottom Ten Rated Characters", characters, 320, 160);
			}
		});
	}

	public void updateGUITopTenReviewedCharacters(final List<LegenCharacterThin> characters) {
		HomePageGUI.get().getMainDisp().asyncExec(new Runnable() {

			public void run() {
				HomePageGUI.get().showTopList("Top Ten Reviewed Characters", characters, 610, 160);
			}
		});
	}

	public void updateGUIWithCharacterReview(final Review review, final Integer characterID) {
		HomePageGUI.get().getMainDisp().asyncExec(new Runnable() {

			public void run() {
				HomePageGUI.get().characterPages.get(characterID).getCharGUI().updateCharacterReviews(review);
			}
		});
	}

	public void updateGUIFinishedUpdatingDBFromFreebase() {
		LoginGUI.get().getMainDisp().asyncExec(new Runnable() {

			public void run() {
				UpdateDBGUI.get().closePopup();
			}
		});
	}
}
